package com.haydn.practice.restfulweb.mBean;

import javax.management.*;
import java.lang.management.ManagementFactory;

/**
 * @Author haydn
 * @create 2020/8/27 23:08
 */
public class MBeanAgent {


    public static void main(String[] args)
            throws
            MalformedObjectNameException, NotCompliantMBeanException,
            InstanceAlreadyExistsException, MBeanRegistrationException,
            InterruptedException {

        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        ObjectName helloName = new ObjectName("jmxBean:name=helloHome");
        ObjectName worldName = new ObjectName("jmxBean:name=Trees");

        ObjectName proCodeName = new ObjectName("ProStatusBean:name=proTest1");


        //创建Mbean并且注册到Mbean server中
        server.registerMBean(new Hello(),helloName);
        server.registerMBean(new Hello(),worldName);

        //模拟测试新建的ProductStatus监控Mbean
        server.registerMBean(new Count(),proCodeName);

        Thread.sleep(60*60*1000);


    }
}
